// scan.js
// 移动动画
let animation = wx.createAnimation({});
// 提示音
let innerAudioContext = wx.createInnerAudioContext()
//innerAudioContext.src = '/images/beep.mp3'

Page({
  data: {
    preData: '',
    src: ''
  },
  onLoad: function () {

  },
  onShow() {
    this.donghua()
  },
  donghua() {
    var that = this;
    // 控制向上还是向下移动
    let m = true

    setInterval(function () {
      if (m) {
        animation.translateY(240).step({ duration: 3000 })
        m = !m;
      } else {
        animation.translateY(-10).step({ duration: 3000 })
        m = !m;
      }

      that.setData({
        animation: animation.export()
      })
    }.bind(this), 3000)
  },
  scancode(e) {
    // 提示音
    //  innerAudioContext.play()
    // 校验扫描结果，并处理
    if (e) {
      let res = e.detail.result

      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
      prevPage.setData({
        preData: res
      })

      setTimeout(function () {
        wx.navigateBack({
          delta: 1
        });
      }, 1000);
    }

  },

  onPhone() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        // this.scancode(result.tempFilePaths[0])
      },

    });

  },

  onBack() {
    wx.navigateBack({
      delta: 1
    });
  },

})

